package com.gu.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.gu.VO.LayuiVO;
import com.gu.VO.ServerResponse;
import com.gu.entity.VehicleInfo;
import com.gu.entity.VehicleRefuelingRule;
import com.gu.service.VehicleInfoService;
import com.gu.service.VehicleRefuelingInfoService;
import com.gu.service.VehicleRefuelingRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @Author: gusongliao
 * @Description: 车辆加油控制类
 * @createDate 2023/01/05 19:32
 */
@Controller
@RequestMapping("/vehicleRefuelingRule")
public class VehicleRefuelingRuleController {

    @Autowired
    private VehicleRefuelingRuleService vehicleRefuelingRuleService;

    @RequestMapping("/vehicleRefuelingRuleList")
    @ResponseBody
    public LayuiVO userList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "15") Integer pageSize,Integer status) throws UnsupportedEncodingException {
        PageInfo ruleList = vehicleRefuelingRuleService.ruleList(pageNum, pageSize, status);
        return LayuiVO.success(ruleList.getTotal(),ruleList.getList());
    }

    @RequestMapping("/updateRefuelingRule")
    @ResponseBody
    public ServerResponse getAllVehicleInfo(String record) {
        VehicleRefuelingRule vehicleRefuelingRule = JSON.parseObject(record, VehicleRefuelingRule.class);
        return vehicleRefuelingRuleService.updateRule(vehicleRefuelingRule);
    }



}
